using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace InventorySystem
{
    [System.Serializable]
    public class InventorySlot
    {
        // 物品槽状态改变事件
        // public event System.EventHandler<InventorySlotStateChangedArgs> StateChanged;
        public event EventHandler<(ItemStack,bool)> StateChanged;

        public ItemDefinition Item{
            get => _state.Item;
        }
        // 物品堆栈状态
        [SerializeField]
        private ItemStack _state;

        // 物品槽是否处于激活状态
        private bool _active;

        // 物品堆栈状态属性
        public ItemStack State
        {
            get => _state;
            set
            {
                _state = value;
                NotifyAboutStateChange();
            }
        }

        // 物品槽激活状态属性
        public bool Active
        {
            get => _active;
            set
            {
                _active = value;
                NotifyAboutStateChange();
            }
        }

        // 物品数量属性
        public int NumberOfItems
        {
            get => _state.NumberOfItems;
            set
            {
                _state.NumberOfItems = value;
                NotifyAboutStateChange();
            }
        }

        // 判断物品槽是否有物品（即物品堆栈中的物品不为空）
        public bool HasItem => _state?.Item != null;

        // 清空物品槽
        public void Clear()
        {
            State = null;
        }

        // 通知物品槽状态改变
        private void NotifyAboutStateChange()
        {
            // StateChanged?.Invoke(this, new InventorySlotStateChangedArgs(_state, _active));
            StateChanged?.Invoke(this, (_state, _active));
        }
    }
}
